home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / DynaDoodle / Spiral.bproj / Spiral.m < prev   
Text File  |  1993-12-14  |  3KB  |  101 lines

  1. /**------------------------------------*------------------------------------**
  2.     RELEASED TO THE PUBLIC DOMAIN BY CODEWORKS DEVELOPMENT, DECEMBER 1993.
  3.     You may freely copy, distribute and reuse the code in this example. Codeworks disclaims any warranty of any kind, expressed or implied, as to its fitness for any particular use.
  4.     Author:  Andrew Vyrros, av@codeworks.com
  5.  **------------------------------------*------------------------------------**/
  6. /**------------------------------------*------------------------------------**
  7.     File:    Spiral.m
  8.     Project: DynaDoodle/Spiral.bproj
  9.     Info:    Implementation of the Spiral class.
  10.  **------------------------------------*------------------------------------**/
  11.  
  12. #import "Spiral.h"
  13. #import <appkit/appkit.h>
  14.  
  15.  
  16. #define NAME NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Spiral class]], "Name", "Spiral", "Name of Spiral Doodle")
  17. #define DESCRIPTION NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Spiral class]], "Description", "A psuedo-spiral curve. You have control over the number of loops and the line width.", "Description of Spiral Doodle")
  18.  
  19.  
  20. @implementation Spiral
  21.  
  22.  
  23. - initFrame:(const NXRect *)f
  24. {
  25.   [super initFrame:f];
  26.   numLoops = 10.0;
  27.   lineWidth = 1.0;
  28.   return self;
  29. }
  30.  
  31.  
  32. - didLoadNib
  33. {
  34.   numLoops = [numLoopsSlider intValue];
  35.   lineWidth = [lineWidthSlider floatValue];
  36.   return self;
  37. }
  38.  
  39.  
  40. - drawSelf:(const NXRect *)rects :(int)numRects
  41. {
  42.   NXPoint             step;
  43.   NXCoord             xCenter,
  44.                       l,
  45.                       r,
  46.                       b,
  47.                       t;
  48.   int                 loop;
  49.   
  50.   NXSetColor(backgroundColor);
  51.   NXRectFill(&bounds);
  52.   NXSetColor(foregroundColor);
  53.  
  54.   PSsetlinewidth(lineWidth);
  55.   
  56.   step.x = bounds.size.width / numLoops / 2.0;
  57.   step.y = bounds.size.height / numLoops / 2.0;
  58.   xCenter = bounds.origin.x + bounds.size.width / 2.0;
  59.   l = bounds.origin.x - step.x * 0.25;
  60.   r = bounds.origin.x + bounds.size.width + step.x * 0.75;
  61.   b = bounds.origin.y - step.y * 0.5;
  62.   t = bounds.origin.y + bounds.size.height;
  63.   
  64.   loop = numLoops;
  65.   while (loop--)
  66.   {
  67.     r -= step.x;
  68.     b += step.y;
  69.     PSmoveto(xCenter, t);
  70.     PScurveto(r, t, r, b, xCenter, b);
  71.     PSstroke();
  72.     
  73.     l += step.x;
  74.     t -= step.y;
  75.     PSmoveto(xCenter, b);
  76.     PScurveto(l, b, l, t, xCenter, t);  
  77.     PSstroke();
  78.   }
  79.   
  80.   return self;
  81. }
  82.  
  83.  
  84. - takeNumLoopsFrom:sender
  85. {
  86.   numLoops = [[sender selectedCell] intValue];
  87.   [self update];
  88.   return self;
  89. }
  90.  
  91.  
  92. - takeLineWidthFrom:sender
  93. {
  94.   lineWidth = [[sender selectedCell] floatValue];
  95.   [self update];
  96.   return self;
  97. }
  98.  
  99.  
  100. @end
  101.